package com.zl.smartmall.library.po;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class ProductEvaluationInfo {

	private int commentId;// 评价的id，需要加载更多的时候，请取列表里最后的id为lastid
	private int score;// 评分，0到10分，共5颗星，目前没有使用这一块，备用
	private int uid;// 评价人的uid
	private long commentTime;// 评价发表的时间
	private String face;// 评价人的头像
	private String nickname;// 评价人的昵称
	private String commentContent;// 评价的正文，可能为空字符串
	private List<PictureInfo> pictures;// 图片，无图则是空

	public int getCommentId() {
		return commentId;
	}

	public void setCommentId(int commentId) {
		this.commentId = commentId;
	}

	public int getScore() {
		return score;
	}

	public void setScore(int score) {
		this.score = score;
	}

	public int getUid() {
		return uid;
	}

	public void setUid(int uid) {
		this.uid = uid;
	}

	public long getCommentTime() {
		return commentTime;
	}

	public void setCommentTime(long commentTime) {
		this.commentTime = commentTime;
	}

	public String getFace() {
		return face;
	}

	public void setFace(String face) {
		this.face = face;
	}

	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public String getCommentContent() {
		return commentContent;
	}

	public void setCommentContent(String commentContent) {
		this.commentContent = commentContent;
	}

	public List<PictureInfo> getPictures() {
		return pictures;
	}

	public void setPictures(List<PictureInfo> pictures) {
		this.pictures = pictures;
	}
	
	public static List<ProductEvaluationInfo> parse(JSONArray jsonArray) throws JSONException{
		List<ProductEvaluationInfo> comments = new ArrayList<ProductEvaluationInfo>();
		if(jsonArray != null && jsonArray.length() > 0) {
			for(int i = 0; i < jsonArray.length(); i++) {
				JSONObject jsonObject = jsonArray.getJSONObject(i);
				comments.add(parseObject(jsonObject));
			}
		}
		
		return comments;
		
	}
	
	public static ProductEvaluationInfo parseObject(JSONObject jsonObject) throws JSONException {
		ProductEvaluationInfo comment = new ProductEvaluationInfo();
		comment.commentContent = jsonObject.getString("contents");
		comment.commentId = jsonObject.getInt("id");
		comment.commentTime = jsonObject.getLong("dateline");
		comment.face = jsonObject.getString("face");
		comment.nickname = jsonObject.getString("nickname");
		comment.score = jsonObject.getInt("scores");
		comment.uid = jsonObject.getInt("uid");
		comment.pictures = PictureInfo.parse(jsonObject.getJSONArray("pics"));
		
		return comment;
	}

}
